﻿namespace Ex03.GarageLogic
{
    using System;
    using System.Collections.Generic;
    using System.Text;

    public enum eCarColors
    {
        Yellow = 1,
        Red = 2,
        Silver = 3,
        White = 4
    }

    public enum eCarNumberOfDoors
    {
        Two = 2,
        Three = 3,
        Four = 4,
        Five = 5
    }

    internal class Car : Vehicle
    {
        #region Messages
        private const string k_StringNotDeinedInCarColorEnum = "{0} is not an allowed color option.";
        private const string k_StringNotDeinedInNumberOfDoorsEnum = "{0} is not an allowed amount of doors. (2, 3, 4 or 5)";
        private const string k_CarColor = "Car color (1 - Yellow, 2 - Red, 3 - Silver, 4 - White): ";
        private const string k_CarNumberOfDoors = "Number of doors: ";
        private const string k_DisplayCarColor = "Car color: ";
        private const string k_DisplayCarNumberOfDoors = "Number of doors: ";
        #endregion

        #region Data Members
        private eCarColors m_carColor;
        private eCarNumberOfDoors m_carNumberOfDoors;
        #endregion

        #region Constractors

        /// <summary>
        /// A constractor of car take 3 parametes
        /// </summary>
        /// <param name="i_LicenseNumber">The license number of the car <remarks>Can take numbers and digits</remarks></param>
        /// <param name="i_Engine">The engine of the car</param>
        /// <param name="i_NumOfWheels">The number of the wheels based on <see cref="Wheel"/>'s class</param>
        /// <param name="i_MaxPSI"></param>
        public Car(string i_LicenseNumber, Engine i_Engine, int i_NumOfWheels, float i_MaxPSI)
            : base(i_LicenseNumber, i_Engine, i_NumOfWheels, i_MaxPSI)
        {
        }
        #endregion

        #region Properties
        public string CarColor 
        {
            get { return this.m_carColor.ToString(); }
            set
            {
                try
                {
                    eCarColors newCarColor = (eCarColors)Enum.Parse(typeof(eCarColors), value);
                    if (!Enum.IsDefined(typeof(eCarColors), newCarColor))
                    {
                        throw new FormatException(string.Format(k_StringNotDeinedInCarColorEnum, value));
                    }
                    else
                    {
                        this.m_carColor = newCarColor;
                    }
                }
                catch (Exception ex)
                {
                    throw new FormatException(string.Format(k_StringNotDeinedInCarColorEnum, value), ex);
                }
            }
        }

        public string CarNumberOfDoors
        {
            get { return this.m_carNumberOfDoors.ToString(); }
            set
            {
                try
                {
                    eCarNumberOfDoors newCarDoorsNumber = (eCarNumberOfDoors)Enum.Parse(typeof(eCarNumberOfDoors), value);
                    if (!Enum.IsDefined(typeof(eCarNumberOfDoors), newCarDoorsNumber))
                    {
                        throw new FormatException(string.Format(k_StringNotDeinedInNumberOfDoorsEnum, value));
                    }
                    else
                    {
                        this.m_carNumberOfDoors = newCarDoorsNumber;
                    }
                }
                catch (Exception ex)
                {
                    throw new FormatException(string.Format(k_StringNotDeinedInNumberOfDoorsEnum, value), ex);
                }
            }
        }
        #endregion

        #region Public Methods
        public override void GetAllDetails(ref List<string> io_ListOfVehicleDetails)
        {
            base.GetAllDetails(ref io_ListOfVehicleDetails);
            io_ListOfVehicleDetails.Add(string.Format(GarageLogic.s_PrintParameter, k_DisplayCarColor, this.CarColor));
            io_ListOfVehicleDetails.Add(string.Format(GarageLogic.s_PrintParameter, k_DisplayCarNumberOfDoors, this.CarNumberOfDoors));
            base.GetEngineAndWheelsDetails(ref io_ListOfVehicleDetails);
        }

        public override void GetClassParametersNeededToCreate(ref List<string> io_ListOfParameters)
        {
            base.GetClassParametersNeededToCreate(ref io_ListOfParameters);

            io_ListOfParameters.Add(k_CarColor);
            io_ListOfParameters.Add(k_CarNumberOfDoors);
        }

        public override void SetClassByParameters(ref Dictionary<string, string> io_Parameters)
        {
            base.SetClassByParameters(ref io_Parameters);

            if (GarageLogic.KeyFoundInDictionaryAndNotEmptyOrNull(io_Parameters, k_CarColor))
            {
                this.CarColor = io_Parameters[k_CarColor];
                io_Parameters[k_CarColor] = string.Empty;
            }

            if (GarageLogic.KeyFoundInDictionaryAndNotEmptyOrNull(io_Parameters, k_CarNumberOfDoors))
            {
                this.CarNumberOfDoors = io_Parameters[k_CarNumberOfDoors];
                io_Parameters[k_CarNumberOfDoors] = string.Empty;
            }
        }
        #endregion
    }
}
